package com.zzw.bridge.business.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzw.bridge.business.dao.ZzwFileReportAssociationDao;
import com.zzw.bridge.business.dto.FileReportQueryDTO;
import com.zzw.bridge.business.dto.LikeFileDTO;
import com.zzw.bridge.business.service.ZzwFileReportAssociationService;
import com.zzw.bridge.business.vo.FileReportQueryVo;
import com.zzw.bridge.common.entitys.business.ZzwFileReportAssociationEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZzwFileReportAssociationServiceImpl extends ServiceImpl<ZzwFileReportAssociationDao, ZzwFileReportAssociationEntity> implements ZzwFileReportAssociationService {


    @Override
    public Page<FileReportQueryVo> queryPage(FileReportQueryDTO dto) {
        Page<FileReportQueryVo> page = new Page<>(dto.getPage(), dto.getSize());
        page=baseMapper.selectByPage(page,dto);
        return page;
    }

    @Override
    public FileReportQueryVo queryByReportId(String reportId) {
        LambdaQueryWrapper<ZzwFileReportAssociationEntity> query = Wrappers.lambdaQuery();
        query.eq(ZzwFileReportAssociationEntity::getReportId,reportId)
                .eq(ZzwFileReportAssociationEntity::getIsDelete,0);
        ZzwFileReportAssociationEntity entity = baseMapper.selectOne(query);
        FileReportQueryVo vo = new FileReportQueryVo();
        BeanUtil.copyProperties(entity,vo);
        return vo;
    }

    @Override
    public Boolean saveBatchByList(List<ZzwFileReportAssociationEntity> list) {
        try {
            baseMapper.insertBatchByList(list);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public List<FileReportQueryVo> queryAllByFileSuffix(LikeFileDTO dto) {
        return baseMapper.selectAllByFileSuffix(dto);
    }
}
